//需要绑定手机号(伪登录)的路由
const needLoginArr = [
	'/pages2/points-detail/points-detail',
	'/pages2/shop-cart/shop-cart',
	'/pages2/shop-order/shop-order',
	'/pages2/shop-confirm/shop-confirm',
	'/pages2/coupon/coupon',
	'/pages2/coupon-center/coupon-center',
	'/pages2/shop-address/shop-address',
	'/pages2/hotel-see-record/hotel-see-record',
	'/pages2/hotel-my-comment/hotel-my-comment',
	'/pages2/hotel-contact/hotel-contact',
	'/pages2/hotel-invoice/hotel-invoice',
	'/pages2/feedback/feedback',
	'/pages3/center/center',
	'/pages3/login/login',
	'/pages2/hotel-member/hotel-member',
]

//跳转tab页面
export const to_switch = (route = 'page/index/index') => {
	uni.switchTab({
		url: route
	});
}
//普通页面跳转
export const to_link = (route,params) => {
	let user_info = uni.getStorageSync('user_info')
	var value = route
	if (value.indexOf('?') > -1) {
		value = (value.split('?'))[0]
	}
	if (needLoginArr.indexOf(value) != -1 && user_info.if_need_regist == 1) {  
		uni.$emit('login')
		return false;
	}
	
	let url = route
	uni.navigateTo({
		url: url,
		success: function(res) {
		    // 通过eventChannel向被打开页面传送数据
		    res.eventChannel.emit('extendDataEmit',params)
		  }
	});
}

//关闭打开新页面
export const to_redirect = (route) => {
	let url = route
	uni.redirectTo({
		url: url
	});
}

export const to_back = (delta = 1) => {
	uni.navigateBack({
		delta: delta
	})
}
//弹框提示
export const msg = (title, callback, time = 1500) => {
	uni.showToast({
		title: title || '',
		mask: true,
		icon: 'none'
	})
	if (typeof callback == 'function') {
		setTimeout(() => {
			callback()
		}, time)
	}
}

//loadding弹框
export const loading = (time = 10000, msg = '加载中') => {
	uni.showLoading({
		title: msg,
		mask: 'true'
	})
	setTimeout(() => {
		uni.hideLoading()
	}, time)
}

//预览图片
export const previewImage = (urls=[], current=0) => {
	if(typeof urls == 'string'){
		let url = [urls]
		urls = url
	}

	uni.previewImage({
		urls: urls,
		current:current
	});
}
